package com.akina.matchsystem.utils;

import cn.hutool.core.util.RandomUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class EmailUtils {


    @Resource
    private  JavaMailSender sender;

    public static String generateCode(){
        return  RandomUtil.randomNumbers(6);
    }

    public void sendCode(String toEmail,String code) {

    SimpleMailMessage message = new SimpleMailMessage();
    // 发送邮件的标题
    message.setSubject("【验证码】");

    // 发送邮件的内容
    message.setText("你的验证码为" + code +
            "如非本人操作，请忽略此邮件，由此给您带来的不便请谅解!"
    );
    // 指定要接收邮件的用户邮箱账号
    message.setTo(toEmail);
    // 发送邮件的邮箱账号
    message.setFrom("1826763338@qq.com");
    // 调用send方法发送邮件即可
    sender.send(message);

    }

}
